package com.huqingshan.LenMore.controller.api;

import com.huqingshan.LenMore.model.dto.OrdersDTO;
import com.huqingshan.LenMore.model.enums.ORDERSTATUS;
import com.huqingshan.LenMore.model.enums.PAYTYPE;
import com.huqingshan.LenMore.model.enums.SORTENUM;
import com.huqingshan.LenMore.service.OrdersService;
import com.huqingshan.LenMore.utils.core.BeanUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/orders")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    @ApiOperation("查询所有订单")
    @RequestMapping("")
    public List<OrdersDTO> findAll(
            @RequestParam(name = "page", required = true, defaultValue = "1") Integer page,
            @RequestParam(name = "size", required = true, defaultValue = "4") Integer size,
            @RequestParam(value = "sort",defaultValue = "DESC") SORTENUM sort,
            @RequestParam(value = "orderstatus",required = false) ORDERSTATUS orderstatus,
            @RequestParam(value = "paytype",required = false) PAYTYPE paytype)
    {

        return BeanUtils.mapAsList(ordersService.findAll(page, size,sort,orderstatus,paytype),OrdersDTO.class);

    }

    @ApiOperation("根据订单id查询")
    @RequestMapping(value = "",params = {"id"})
    public OrdersDTO findById(
            @RequestParam("id") String ordersId)
    {
        return BeanUtils.map(ordersService.findById(ordersId), OrdersDTO.class);
    }

    @ApiOperation("根据订单名查询")
    @GetMapping(value = "",params = {"name"})
    public OrdersDTO findByName(
            @RequestParam(value = "name") String name)
    {
        return BeanUtils.map(null,OrdersDTO.class);
    }

}
